/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tbgb.components.twodimesion.point2dimplements;

import tbgb.common.TBNumber;

/**
 *
 * @author LưuQuang
 */
public class Point2D {
    public static final Point2D ZERO = new Point2D();
    
    public final TBNumber X, Y;
    
    public Point2D()
    {
        X = new TBNumber();
        Y = new TBNumber();
    }
    
    public Point2D(int x, int y)
    {
        this.X = new TBNumber(x);
        this.Y = new TBNumber(y);
    }
    
    public Point2D(float x, float y)
    {
        this.X = new TBNumber(x);
        this.Y = new TBNumber(y);
    }
    
    public Point2D(TBNumber x, TBNumber y)
    {
        this.X = x.copy();
        this.Y = y.copy();
    }
    
    public Point2D(Point2D p)
    {
        this.X = p.X.copy();
        this.Y = p.Y.copy();
    }
    
    public void set(TBNumber x, TBNumber y)
    {
        this.X.set(x);
        this.Y.set(y);
    }
    
    public void set(int x, int y)
    {
        this.X.set(x);
        this.Y.set(y);
    }
    
    public void set(float x, float y)
    {
        this.X.set(x);
        this.Y.set(y);
    }
    
    public void set(Point2D p)
    {
        this.X.set(p.X);
        this.Y.set(p.Y);
    }
    
    public void add(TBNumber dx, TBNumber dy)
    {
        X.saAdd(dx);
        Y.saAdd(dy);
    }
    
    public void multiply(TBNumber n)
    {
        X.saMult(n);
        Y.saMult(n);
    }
    
    public void toZero()
    {
        this.X.set(0);
        this.Y.set(0);
    }
    
    public boolean isZero()
    {
        return (0 == this.X.getInt() || 0 == this.Y.getInt());
    }
    
    public void normalize()
    {
        
    }
    
    public TBNumber getSquaredLength()
    {
        TBNumber result = X.mult(X);
        result.saAdd(Y.mult(Y));
        
        return result;
    }
}
